package com.fendaren.controller;

import com.fendaren.pojo.bo.ShopcartBO;
import com.fendaren.pojo.vo.ShopcartVO;
import com.fendaren.utils.JSONResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("shopcart")
public class ShopcatController {

    @PostMapping("/add")
    public JSONResult add(@RequestParam String userId,
                          @RequestBody ShopcartBO shopcartBO,
                          HttpServletRequest request,
                          HttpServletResponse response) {

        if(StringUtils.isBlank(userId)){
            return JSONResult.errorMsg("");
        }

        // TODO 前端用户在登陆的情况下，添加商品到购物车，会同时在后端同步购物车到Redis缓存
        return JSONResult.ok();
    }

    @PostMapping("/del")
    public JSONResult del(@RequestParam String userId,
                          @RequestBody String itemSpecId,
                          HttpServletRequest request,
                          HttpServletResponse response) {

        if(StringUtils.isBlank(userId)||StringUtils.isBlank(itemSpecId)){
            return JSONResult.errorMsg("参数不能为空");
        }

        // TODO 用户在页面删除购物车中的商品数据
        return JSONResult.ok();
    }
}
